#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from app import create_app
from models import db, Problem
import json

def list_problems():
    """列出题库中的所有题目"""
    app = create_app()
    
    with app.app_context():
        problems = Problem.query.all()
        
        print(f"题库中共有 {len(problems)} 道题目")
        print("=" * 80)
        
        for i, problem in enumerate(problems, 1):
            print(f"{i:2d}. {problem.title}")
            print(f"    类型: {problem.type}")
            print(f"    难度: {problem.difficulty}")
            print(f"    创建者ID: {problem.created_by}")
            print(f"    状态: {problem.status}")
            print(f"    创建时间: {problem.created_at}")
            
            # 显示测试用例数量
            if problem.test_cases:
                test_cases = json.loads(problem.test_cases)
                print(f"    测试用例: {len(test_cases)} 个")
            
            # 显示选项数量（选择题）
            if problem.options:
                options = json.loads(problem.options)
                print(f"    选项: {len(options)} 个")
            
            print("-" * 80)

if __name__ == '__main__':
    list_problems()
